package cn.hinglo.gameclaw.admin.dao;

import cn.hinglo.gameclaw.data.dbdao.MyMapper;
import cn.hinglo.gameclaw.user.bean.Morder;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @createTime: 2018/5/22
 * @author: HingLo
 * @description: 充值订单Dao
 */
@Repository
public interface MorderDao extends MyMapper<Morder> {
    /**
     * 支付成功后，修改用户的钻石数量
     *
     * @param userId   用户的userId
     * @param gold     钻石
     * @param giveGold 赠送的钻石
     * @return 返回是否修改成功
     */
    @Update("update user_info set gold = gold+ #{gold},give_gold = give_gold+#{giveGold} where user_id=#{userId}")
    int updateGoldByUserIdDao(@Param("gold") Integer gold, @Param("giveGold") Integer giveGold, @Param("userId") String userId);

    /**
     * 查询充值订单
     *
     * @param type 支付类型
     * @param date 支付时间
     * @return 返回结果
     */
    @Select("select id,user_id,num,gold,give_gold,pay_date,date,status from morder where status =true and  payment=#{type} and date_format(pay_date,'%y-%m-%d') = date_format(#{date},'%y-%m-%d')")
    List<Map<String, Object>> listDao(@Param("type") int type, @Param("date") Date date);

    /**
     * 充值记录统计
     *
     * @param payment 支付返航时
     * @param start   开始时间
     * @param end     结束时间
     * @return 结果
     */
    @Select("select date_format(date,'%Y-%m-%d') as date, sum(num) as mon from morder where payment=#{payment} and date between #{start} and #{end} group by date order by date ")
    List<Map<String, Object>> dataListDao(@Param("payment") int payment, @Param("start") Date start, @Param("end") Date end);

}
